package com.toby.ioc.conditional;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @desc:
 * @author: toby
 * @date: 2019/7/13 1:40
 */
public class TobyCondition implements Condition {
    private static final String TOBY_A_BEAN_NAME = "tobyA";
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //判断容器中是否有TobyA组件
        if(context.getBeanFactory().containsBean(TOBY_A_BEAN_NAME)){
            return true;
        }
        return false;
    }
}
